package com.sxm.yiwei.adapters;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.MyAccountStream;
import com.sxm.yiwei.beans.Stream;
import com.sxm.yiwei.tools.CastTime;

import java.util.List;

/**
 * Created by KuKa on 2017/8/14.
 * 账户流水列表
 */

public class AccountStreamAdapter extends BaseAdapter {
    Context context;
    List<Stream.DataBean> streamList;
    public AccountStreamAdapter(Context context, List<Stream.DataBean> streamList) {
        this.context = context;
        this.streamList=streamList;
    }

    @Override
    public int getCount() {
        return streamList.size()==0?0:streamList.size();
    }

    @Override
    public Object getItem(int position) {
        return streamList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView==null){
            view= View.inflate(context,R.layout.stream_item,null);
            holder = new ViewHolder();
            holder.title = (TextView) view.findViewById(R.id.stream_title);
            holder.time = (TextView) view.findViewById(R.id.stream_time);
            holder.code = (TextView) view.findViewById(R.id.stream_code);
            holder.money = (TextView) view.findViewById(R.id.stream_money);
            view.setTag(holder);
        }else {
            view=convertView;
            holder = (ViewHolder) view.getTag();
        }
        holder.title.setText(streamList.get(position).getTitle());
        holder.code.setText(streamList.get(position).getOrderCode());
        boolean isInflow = streamList.get(position).isIsInflow();
        if (isInflow){
            holder.money.setTextColor(Color.parseColor("#ff0000"));
            holder.money.setText("+"+streamList.get(position).getAmount()+" 元");
        }else {
            holder.money.setTextColor(Color.parseColor("#3F51B5"));
            holder.money.setText("-"+streamList.get(position).getAmount()+" 元");
        }
        holder.time.setText(CastTime.streamTime(streamList.get(position).getCreateTime()));

        return view;

    }
    class ViewHolder{
        TextView title,code,time,money;
    }
}
